/**
 * Created by Administrator on 2017/3/13 0013.
 */
var Page0= {
    create: function () {
        var page = {};
        var tw_whole,tw_t0,tw_t1,tw_img1,tw_img2,tw_img3,tw_logo0,tw_logo1;
        page.ui = new PIXI.DisplayObjectContainer();

        var bg = new PIXI.Sprite(resource['assets/images/p0_bg.png'].texture);
        page.ui.addChild(bg);

        var star0= new PIXI.Sprite(resource['assets/images/star0.png'].texture);
        star0.x=0;
        star0.y=0;
        page.ui.addChild(star0);
        new TWEEN.Tween({alpha:1})
            .to({alpha:0},3000)
            .onUpdate(function () {
                star0.alpha=this.alpha;
            })
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start()

        var star1= new PIXI.Sprite(resource['assets/images/star1.png'].texture);
        star1.x=0;
        star1.y=513;
        page.ui.addChild(star1);
        new TWEEN.Tween({alpha:1})
            .to({alpha:0},2800)
            .onUpdate(function () {
                star1.alpha=this.alpha;
            })
            .delay(1000)
            .repeat(Infinity)
            .yoyo(true)
            .easing(TWEEN.Easing.Cubic.InOut)
            .start()

        var logo0 = new PIXI.Sprite(resource['assets/images/p0_logo0.png'].texture);
        logo0.anchor.set(0.5);
        logo0.x=76;
        logo0.y=35;
        logo0.alpha=0;
        page.ui.addChild(logo0);

        var logo1 = new PIXI.Sprite(resource['assets/images/p0_logo1.png'].texture);
        logo1.anchor.set(0.5);
        logo1.x=370;
        logo1.y=50;
        logo1.alpha=0;
        page.ui.addChild(logo1);

        var  img1 = new PIXI.Sprite(resource['assets/images/p0_img1.png'].texture);
        img1.anchor.set(0.5);
        img1.x=362;
        img1.y=570;
        img1.alpha=0;
        page.ui.addChild(img1);

        var  img2 = new PIXI.Sprite(resource['assets/images/p0_img2.png'].texture);
        img2.anchor.set(72/431,130/166);
        img2.x=282;
        img2.y=551;
        img2.alpha=0;
        page.ui.addChild(img2);
        new TWEEN.Tween({rot:0})
            .to({rot:Math.PI*2},5000)
            .onUpdate(function () {
                img2.rotation=this.rot;
            })
            .repeat(Infinity)
            .easing(TWEEN.Easing.Linear.None)
            .start();

        var  img3 = new PIXI.Sprite(resource['assets/images/p0_img3.png'].texture);
        img3.anchor.set(73/99,240/267);
        img3.x=281;
        img3.y=548;
        img3.alpha=0;
        page.ui.addChild(img3);
        new TWEEN.Tween({rot:0})
            .to({rot:Math.PI*2},12*5000)
            .onUpdate(function () {
                img3.rotation=this.rot;
            })
            .repeat(Infinity)
            .easing(TWEEN.Easing.Linear.None)
            .start();


        var t0x = 370;
        var t0 = new PIXI.Sprite(resource['assets/images/p0_t0.png'].texture);
        t0.x = t0x;
        t0.y = 213;
        t0.alpha = 0;
        t0.anchor.set(0.5);
        page.ui.addChild(t0);

        var t1x = 370;
        var t1 = new PIXI.Sprite(resource['assets/images/p0_t1.png'].texture);
        t1.x = t1x;
        t1.y = 1018;
        t1.alpha = 0;
        t1.anchor.set(0.5);
        page.ui.addChild(t1);

        // var tip= new PIXI.Sprite(resource['assets/images/tip0.png'].texture);
        // tip.x = 370;
        // tip.y = 1088;
        // tip.alpha = 1;
        // tip.anchor.set(0.5);
        // page.ui.addChild(tip);
        // new TWEEN.Tween({y:1088,alpha:1})
        //     .to({y:1088+30,alpha:0.5},600)
        //     .onUpdate(function () {
        //         tip.y=this.y;
        //         tip.alpha=this.alpha;
        //     })
        //     .yoyo(true)
        //     .repeat(Infinity)
        //     .easing(TWEEN.Easing.Cubic.InOut)
        //     .start();
        
        page.In=function () {
            if(tw_whole)
            {
                tw_whole.stop();
                TWEEN.remove(tw_whole);
            }

            tw_logo0=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(0)
                .onUpdate(function () {
                    // t0.scale.x=this.scale;
                    // t0.scale.y=this.scale;
                    logo0.alpha=this.alpha;
                })
                .start();
            tw_logo1=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(0)
                .onUpdate(function () {
                    // t0.scale.x=this.scale;
                    // t0.scale.y=this.scale;
                    logo1.alpha=this.alpha;
                })
                .start();

            tw_t0=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(0)
                .onUpdate(function () {
                    t0.scale.x=this.scale;
                    t0.scale.y=this.scale;
                    t0.alpha=this.alpha;
                })
             .start();

            // tw_img0=new TWEEN.Tween({scale:0,alpha:0})
            //     .to({scale:1,alpha:1})
            //     .delay(0)
            //     .onUpdate(function () {
            //         t0.scale.x=this.scale;
            //         t0.scale.y=this.scale;
            //         t0.alpha=this.alpha;
            //     });
            tw_img1=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},1000)
                .delay(500)
                .easing(TWEEN.Easing.Back.Out)
                .onUpdate(function () {
                    img1.alpha=this.alpha;
                    img1.scale.x=this.scale;
                    img1.scale.y=this.scale;
                })
            .start();

            tw_img2=new TWEEN.Tween({alpha:0})
                .to({scale:1,alpha:1},2000)
                .delay(1000)
                // .easing(TWEEN.Easing.Back.Out)
                .onUpdate(function () {
                    img2.alpha=this.alpha;
                    // img2.scale.x=this.scale;
                    // img2.scale.y=this.scale;

                })
            .start();

            tw_img3=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},2000)
                .delay(1200)
                // .easing(TWEEN.Easing.Back.Out)
                .onUpdate(function () {
                    img3.alpha=this.alpha;
                    // img3.scale.x=this.scale;
                    // img3.scale.y=this.scale;

                })
            .start();


            tw_t1=new TWEEN.Tween({scale:0,alpha:0})
                .to({scale:1,alpha:1},700)
                .delay(1000)
                .onUpdate(function () {
                    t1.scale.x=this.scale;
                    t1.scale.y=this.scale;
                    t1.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Back.Out)
            .start();
        }
        page.Out=function () {
            if(tw_logo0)
            {
                tw_logo0.stop();
            }
            if(tw_logo1)
            {
                tw_logo1.stop();
            }
            if(tw_img1)
            {
                tw_img1.stop();
            }
            if(tw_img2)
            {
                tw_img2.stop();
            }
            if(tw_img3)
            {
                tw_img3.stop();
            }
            if(tw_t0)
            {
                tw_t0.stop();
            }
            if(tw_t1)
            {
                tw_t1.stop();
            }

            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},400)
                .onUpdate(function () {
                    // page.ui.alpha=this.alpha;
                })

                .onComplete(function () {
                    page.ui.alpha=1;
                    t0.alpha=0;
                    t1.alpha=0;
                    img1.alpha=0;
                    img2.alpha=0;
                    img3.alpha=0;
                    logo0.alpha=0;
                    logo1.alpha=0;
                    console.log('sssssssssssss')
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }
        page.myOut=function () {
            tw_whole=new TWEEN.Tween({alpha:1})
                .to({alpha:0},1000)
                .onUpdate(function () {
                    page.ui.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }
        return page;
    }
}